<div class="form wide">

    <?php $form = $this->beginWidget('CActiveForm', array(
    'id' => 'gallery-form',
    'enableAjaxValidation' => false,
    'enableClientValidation' => true,
    'clientOptions' => array(
        'validateOnSubmit' => true,
        'afterValidate'=>"js:function(form,data,hasError){
            $('#msgErrorNoPhoto').hide();
            if (!hasError)
            {
                var allowUpload = true;
                $('#photos .multi-file-row').each(function(){
                    var filename = $.trim($(this).find('.file input[type=hidden]').val());
                    if (filename == '')
                    {
                        allowUpload = false;
                        return allowUpload; 
                    }
                });
                if (allowUpload == false)
                {
                    $('#msgErrorNoPhoto').show();
                    return false;    
                }
                return true;    
            }
            else return false;
        }"
    ),
)); ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php if (!$model->IsNewRecord) echo $form->hiddenField($model, "id"); ?>
    <div class="row">
        <?php echo $form->labelEx($model, 'name'); ?>
        <?php echo $form->textField($model, 'name', array('size' => 60, 'maxlength' => 255)); ?>
        <?php echo $form->error($model, 'name'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'alias'); ?>
        <?php echo $form->textField($model, 'alias', array('size' => 60, 'maxlength' => 255)); ?>
        <?php echo $form->error($model, 'alias'); ?>
    </div>

    <div class="row">
        <label>Photos</label>

        <div id="photos">
            <?php
            $this->widget('Gallery.components.MultiFileWidget', array(
                'model' => $photos,
                'attribute' => 'path',
                'fileOptions' => array(
                    'thumbWidth' => 100,
                    'thumbHeight' => 100,
                )
            ));
            $script = "
jQuery('.multi-file').sortable({
    'update' : function(event,ui){
        jQuery.fn.updateOrder(ui.item);
    }
});
//jQuery('.multi-file').disableSelection();
";
            Yii::app()->clientScript->registerScript(__CLASS__ . '#Sort', $script);
            ?>
        </div>
        <div class="errorMessage" id="msgErrorNoPhoto" style="display: none;">Please select photo(s) completely.</div>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
    </div>

    <?php $this->endWidget(); ?>

</div><!-- form -->
